if(!cell) var cell={};
if(!cell.fn) cell.fn={};

cell.fn.preferences = function(){
	var pub={};
	pub.val=null;
	
	pub.str=function(key,val){
		var obj=key;
		
		if ( val == undefined || key.match(/^\?/)){
			if(key.match(/^!/)){
				cell.fn.preferences.xpcom.clearUserPref(key.replace(/^!/,''));
				return;
			}
			switch (cell.fn.preferences.xpcom.getPrefType(key.replace(/^\?/,''))){
				case 32:
					cell.fn.preferences.getChar(key.replace(/^\?/,''),val);
					return cell.fn.preferences.val;
					break;
				case 64:
					cell.fn.preferences.getInt(key.replace(/^\?/,''),val);
					return cell.fn.preferences.val;
					break;
				case 128:
				default:
					cell.fn.preferences.getBool(key.replace(/^\?/,''),val);
					return cell.fn.preferences.val;
					break;
			} 
			return;
		}else {
			obj = {};
			obj[ key ] = val;
			//this.log(key+val+typeof(val))
		}
		for (var key in obj){
			switch (typeof(obj[key])){
				case 'boolean':
						this.setBool(key,obj[key]);
					//	return this.getBool(key);
					break;
				case 'number':
						this.setInt(key,obj[key]);
				//		return this.getInt(key);
					break;
				default:
					this.setChar(key,obj[key]);
				//	return this.getChar(key);
			}
		}
	};
	
	pub.xpcom=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
	
	pub.setBool=function (aPrefName, aPrefValue){
		try {
			cell.fn.preferences.xpcom.setBoolPref(aPrefName, aPrefValue);
		}catch(e){}
	};

	pub.setChar=function (aPrefName, aPrefValue){
		try{
			var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
			str.data = aPrefValue;
			cell.fn.preferences.xpcom.setComplexValue(aPrefName,Components.interfaces.nsISupportsString, str);
		}catch(e){}
	}

	pub.setInt=function (aPrefName, aPrefValue){
		try{
			cell.fn.preferences.xpcom.setIntPref(aPrefName, aPrefValue);
		}catch(e){ }
	}


	pub.getBool=function (aPrefName, aDefVal) {
		try {
			pub.val=cell.fn.preferences.xpcom.getBoolPref(aPrefName);
		}catch(e){
			pub.val=pub.DefVal(aDefVal);
		}
		return null;
	};

	pub.getInt=function (aPrefName, aDefVal) {
		try{
			pub.val=cell.fn.preferences.xpcom.getIntPref(aPrefName);
		}catch(e){
			pub.val=pub.DefVal(aDefVal);
		}
	}
	
	pub.getChar=function (aPrefName, aDefVal) {
		try{
			pub.val=cell.fn.preferences.xpcom.getComplexValue(aPrefName,Components.interfaces.nsIPrefLocalizedString).data;
		}catch(e){
			pub.val=pub.DefVal(aDefVal);
		}
	}
	
	pub.DefVal=function (val) {
		if(val != undefined){
			pub.val=val;
		}else{
			pub.val=null;
		}
	}
	return pub;
}();
if(!$pref2) var $pref2=function(key,val) {
	return cell.fn.preferences.str(key, val);
}